package com.gopay.bis.ccb.bcdl.operation;

import org.apache.commons.lang3.StringUtils;

import com.gopay.common.constants.bank.CcbConstants;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.ccb.bcdl.BaseReqBody;
import com.gopay.common.domain.bank.ccb.bcdl.querybalance.res.TransResQueryBalanceBody;
import com.gopay.common.exception.GopayException;

public class CcbBcdlQueryBalanceHelper extends CcbBcdlBaseHelper<TransResQueryBalanceBody> {
	
	public TransResQueryBalanceBody queryBalance(BaseReqBody req,SocketTransport bcdlSocketTransport) throws GopayException{
		req.setTxCode("6W0100");
		String xml = getXml(req);
		logger.error("CcbBcdlQueryBalanceHelper queryBalance xml = "+ xml);
		bcdlSocketTransport.setHost(req.getUrl());
		String resXml = (String) bcdlSocketTransport.submit(xml);
		logger.error("CcbBcdlQueryBalanceHelper queryBalance xml = "+ resXml);
		if(StringUtils.isNotBlank(resXml)){
			TransResQueryBalanceBody body = parse(resXml);
			if(body!=null){
				if(!CcbConstants.BCDL_RESULT_CODE_SUCC.equals(body.getReturnCode())){
					logger.error("CcbBcdlQueryBalanceHelper error orderId = " + req.getRequestSn()+ "rspcod =" + body.getReturnCode() +", returnMsg ="+ body.getReturnMsg());
				}
				return body;
			}else{
				logger.error("CcbBcdlQueryBalanceHelper parse error orderId = "+req.getRequestSn());
			}
		}else{
			logger.error("CcbBcdlQueryBalanceHelper resXml is null orderId = "+req.getRequestSn());
		}
		throw new GopayException(ProcCodeConstants.PROC_CODE_100E6049);
	}
	
}
